package com.lugea.common.wrapper;

import java.io.Serializable;

import com.lugea.common.enums.EnumWebRepsonseCode;

/**
 * @author ： enluw
 * 
 * @date 2020-01-27
 * 
 * @描述：
 */
public class WebResponse<T> implements Serializable {
    private static final long serialVersionUID = 6371375044137230680L;
    /**
     * 状态码
     */
    private int code;
    /**
     * 状态信息信息
     */
    private String msg;
    /**
     * 返回信息
     */
    private T data;
    /**
     * 状态结果
     */
    private boolean ret;

    public WebResponse() {
    }

    public WebResponse(int code, T data, boolean ret) {
        this.code = code;
        this.data = data;
        this.ret = ret;
    }

    public WebResponse(int code, String msg, boolean ret) {
        this.code = code;
        this.msg = msg;
        this.ret = ret;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isRet() {
        return ret;
    }

    public void setRet(boolean ret) {
        this.ret = ret;
    }

    public static WebResponse returnFail(int code, String msg) {
        return new WebResponse(code, msg, false);
    }

    public static <T> WebResponse returnSuccess(T data) {
        return new WebResponse(EnumWebRepsonseCode.SUCCESS.getCode(), data, true);
    }
}
